import React, { useState } from "react";
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
} from "@ant-design/icons";
import { Button, Layout, Menu, theme } from "antd";
const { Header, Sider, Content } = Layout;
import Home from "./child/home";
import Shoplist from "./child/shoplist";
import Typelist from "./child/typelist";
import { Switch, Route, Redirect, type RouteComponentProps } from "react-router-dom";
const Admin: React.FC<RouteComponentProps> = (props) => {
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();

  return (
    <Layout>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="inline"
          defaultSelectedKeys={[props.location.pathname]}
          defaultOpenKeys={["",props.location.pathname]}
          items={[
            {
              key: "/admin/home",
              icon: <UserOutlined />,
              label: "首页",
            },
            {
              key: "",
              icon: <VideoCameraOutlined />,
              label: "电子劵管理",
              children: [
                {
                  key: "/admin/shoplist",
                  icon: <UploadOutlined />,
                  label: "优惠劵制作",
                },
                {
                  key: "/admin/typelist",
                  icon: <UploadOutlined />,
                  label: "已发布优惠券",
                },
              ],
            },
          ]}
          onSelect={(value)=>{
            props.history.push(value.key)
          }}
        />
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: colorBgContainer }}>
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: "16px",
              width: 64,
              height: 64,
            }}
          />
        </Header>
        <Content
          style={{
            margin: "24px 16px",
            padding: 24,
            height:"100vh",
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
          <Switch>
            <Route path="/admin/shoplist" component={Shoplist}></Route>
            <Route path="/admin/typelist" component={Typelist}></Route>
            <Route path="/admin/home" component={Home}></Route>
            <Redirect to="/admin/home" from="/admin"></Redirect>
          </Switch>
        </Content>
      </Layout>
    </Layout>
  );
};

export default Admin;
